package com.zjsru.oneDay202212;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author: CookLee
 * @Date: 2022/12/13
 * 判断句子是否为全字母句:全字母句 指包含英语字母表中每个字母至少一次的句子。
 *
 * 输入：sentence = "thequickbrownfoxjumpsoverthelazydog"
 * 输出：true
 * 解释：sentence 包含英语字母表中每个字母至少一次。
 *
 * 输入：sentence = "leetcode"
 * 输出：false
 *
 */
public class CheckIfPangram {
    
    /**
     * 模拟
     */
    public boolean checkIfPangram(String sentence) {
        int[] cnt = new int[26];
        for (int i = 0; i < sentence.length(); i++) {
            cnt[sentence.charAt(i) - 'a']++;
        }
        for (int i : cnt) {
            if (i == 0) {
                return false;
            }
        }
        return true;
    }
    
    
    /**
     * 哈希map存储
     */
    public boolean checkIfPangram2(String sentence) {
        Map<Character, Integer> map = new HashMap<>(26);
        for (int i = 0; i < sentence.length(); i++) {
            map.put(sentence.charAt(i), map.getOrDefault(sentence.charAt(i), 0) + 1);
        }
        return map.size() >= 26;
    }
    
    /**
     * 针对第一种方法的代码简化，但是时间和内存运行时间反而变慢
     */
    public boolean checkIfPangram3(String sentence) {
        int[] cnts = new int[26];
        for (int i = 0; i < sentence.length(); i++) {
            //统计是否出现，不要求计数出现次数
            cnts[sentence.charAt(i) - 'a'] = 1;
        }
        return Arrays.stream(cnts).sum() == 26;
    }
    
    public static void main(String[] args) {
        CheckIfPangram checkIfPangram = new CheckIfPangram();
        String sentence = "jwtucoucmdfwxxqnxzkaxoglszmfrcvjoiunqqausaxxaaijyqdqgvdnqcaihwilqkpivenpnekioyqujrdrovqrlxovcucjqzjsxmllfgndfprctxvxwlzjtciqxgsxfwhmuzqvlksyuztoetyjugmswfjtawwaqmwyxmvo";
        System.out.println(checkIfPangram.checkIfPangram(sentence));
    }
}
